export const SET_THEME = 'setTheme';
export const SKIP_GQI_TUTORIAL = 'skippedGQITutorial';
export const SKIP_BASIC_TUTORIAL = "skippedBasicIndicatorTutorial";
export const SET_LEFTDRAWER_MENU_INDEX = 'setLeftDrawerMenuIndex';
export const DASHBOARD_TIPS = 'dashboardTips';

// To set the current theme to either dark or light
export const setLightMode = (value) => ({
  type: SET_THEME,
  value
});

// To set the user preference to skip GQI Tutorial
export const skipGQITutorial = () => ({
  type: SKIP_GQI_TUTORIAL,
})

// To set the user preference to skip GQI Tutorial
export const skipBasicIndicatorTutorial = () => ({
  type: SKIP_BASIC_TUTORIAL,
})

export const setLeftDrawerMenuIndex = (value) => ({
  type: SET_LEFTDRAWER_MENU_INDEX,
  payload: {
    value
  }
})
export const dashboardTips = (value) => ({
  type: DASHBOARD_TIPS,
  payload: {
    value
  }
})

// Initial state for User Preferences
const initialState = {
  darkMode: true,
  gqiEditorTutorialSkip: true,
  basicIndicatorTutorialSkip: true,
  leftDrawerMenuIndex: 1,
  dashboardTips: true
};

export default function userPreferencesReducer(state = initialState, action) {
  switch (action.type) {
    // Themes
    case SET_THEME:
      return {...state, darkMode: action.value}
    // Tutorials
    case SKIP_GQI_TUTORIAL:
      return {...state, gqiEditorTutorialSkip: !state.gqiEditorTutorialSkip}
    case SKIP_BASIC_TUTORIAL:
      return {...state, basicIndicatorTutorialSkip: !state.basicIndicatorTutorialSkip}
    // Menu
    case SET_LEFTDRAWER_MENU_INDEX:
      return {...state, leftDrawerMenuIndex: action.payload.value}
    case DASHBOARD_TIPS:
      return {...state, dashboardTips: action.payload.value}
    default:
      return state;
  }
}